# -*- coding: utf-8 -*-

###########################################################################
## Python code generated with wxFormBuilder (version Oct 26 2018)
## http://www.wxformbuilder.org/
##
## PLEASE DO *NOT* EDIT THIS FILE!
###########################################################################
##
# UI refs https://wxpython.org/pages/overview/
##

import wx
import wx.xrc
import os
from lib.ruku import excelWork

###########################################################################
## Class MainWin
###########################################################################

class MainWin ( wx.Frame ):

  def __init__( self, parent ):
    wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"京东仓入库", pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

    self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )

    main_wrap = wx.BoxSizer( wx.VERTICAL )

    self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, u"选择入仓计划表", wx.DefaultPosition, wx.DefaultSize, 0 )
    self.m_staticText1.Wrap( -1 )

    main_wrap.Add( self.m_staticText1, 0, wx.ALL, 5 )

    self.m_pick_input = wx.FilePickerCtrl( self, wx.ID_ANY, wx.EmptyString, u"选择文件", u"*.xls;*.xlsx", wx.Point( -1,-1 ), wx.DefaultSize, wx.FLP_DEFAULT_STYLE )
    self.m_pick_input.SetMinSize( wx.Size( 400,-1 ) )

    main_wrap.Add( self.m_pick_input, 0, wx.ALL, 5 )

    self.m_staticText3 = wx.StaticText( self, wx.ID_ANY, u"输出目录", wx.DefaultPosition, wx.DefaultSize, 0 )
    self.m_staticText3.Wrap( -1 )

    main_wrap.Add( self.m_staticText3, 0, wx.ALL, 5 )

    self.m_pick_output_dir = wx.DirPickerCtrl( self, wx.ID_ANY, os.getcwd(), u"选择目录", wx.DefaultPosition, wx.DefaultSize, wx.DIRP_DEFAULT_STYLE )
    self.m_pick_output_dir.SetMinSize( wx.Size( 400,-1 ) )

    main_wrap.Add( self.m_pick_output_dir, 0, wx.ALL, 5 )

    self.m_button_start = wx.Button( self, wx.ID_ANY, u"开始", wx.DefaultPosition, wx.DefaultSize, 0 )
    main_wrap.Add( self.m_button_start, 0, wx.ALL, 5 )


    self.SetSizer( main_wrap )
    self.Layout()
    self.m_statusBar = self.CreateStatusBar( 1, wx.STB_SIZEGRIP, wx.ID_ANY )

    self.Centre( wx.BOTH )

    # Connect Events
    self.Bind( wx.EVT_ACTIVATE_APP, self.init )
    self.m_pick_input.Bind( wx.EVT_FILEPICKER_CHANGED, self.setInput )
    self.m_pick_output_dir.Bind( wx.EVT_DIRPICKER_CHANGED, self.setOutput )
    self.m_button_start.Bind( wx.EVT_BUTTON, self.start )

  def __del__( self ):
    pass


  # Virtual event handlers, overide them in your derived class
  def init( self, event ):
    self.SetStatusText(u"未开始")

  def setInput( self, event ):
    self.SetStatusText(u'未开始')

  def setOutput( self, event ):
    event.Skip()

  def start( self, event ):
    # event.Skip()
    inFile = self.m_pick_input.GetPath()
    outDir = self.m_pick_output_dir.GetPath()
    if not inFile:
      self.SetStatusText(u"请选择入库计划表")
    elif not os.path.isfile(inFile):
      self.SetStatusText(u"文件不存在, 请重新选择")
    else:
      # 开始
      self.SetStatusText(u"努力分析中, 请等待...")
      result, gzNew, bjNew, shNew, whNew = excelWork(inFile, outDir)
      if result:
        self.SetStatusText("完成. 广州{}款, 北京{}款, 上海{}款, 武汉{}款".format(gzNew, bjNew, shNew, whNew))


if __name__ == '__main__':
    # When this module is run (not imported) then create the app, the
    # frame, show it, and start the event loop.

    app = wx.App()
    frm = MainWin(None)
    frm.Show()
    app.MainLoop()